<?php

namespace App\Http\Requests\Entity\Pm;

use App\Http\Requests\Request;

class MeteringPeriodRequest extends Request
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch($this->method())
        {
            case 'GET':
            case 'DELETE':
            {
                return [];
            }
            // Crate
            case 'POST':
            {
                return [
                    'name' => 'required|max:100',
                    'title' => 'max:100',
                    'short_desc' => 'required|max:100',
                    'unit' => 'required|max:100',
                    'amount' => 'required|integer',
                    'expiry_date_id' => 'required_if:unit,7'
                ];
            }
            // UPDATE
            case 'PUT':
            case 'PATCH':
            {
                // $id = $this->route('metering_periods');
                return [
                    'name' => 'required|max:100',
                    'title' => 'max:100',
                    'short_desc' => 'required|max:100',
                    'unit' => 'required|max:100',
                    'amount' => 'required|integer',
                    'expiry_date_id' => 'required_if:unit,7'
                ];
            }
            default:
                break;
        }
    }
     public function messages()
    {
        return [
            'name.required'       => '计费规则名 不能为空',
            'name.max'       => '计费规则名 不能大于100个字符',
            'short_desc.required' => '描述 不能为空',
            'title.max'       => '标题 不能大于100个字符',
            'unit.required'       => '单位 不能为空',
            'amount.required'     => '数量 不能为空',
            'expiry_date_id.required'  => '当单位是 “次“ 时按次有效时间 不能为空',
        ];
    }
}
